package com.finesys.backend.common.utils;

import java.io.*;
import java.util.List;

/**
 * @Title: FileUtil
 * @Description:
 * @Author: bin.f
 * @Date: 10:132020/12/3
 **/
public class FileUtil {

    public static boolean writeContent(String c,String dirName,String fileName){

        File f=new File(dirName);
        if (!f.exists())
        {
            f.mkdirs();
        }
        try {
            FileOutputStream fos = new FileOutputStream( dirName+File.separator+fileName,true);
            OutputStreamWriter writer = new OutputStreamWriter(fos);
            writer.write(c);
            writer.close();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    public static String readFile(String filename){
        String content = "";
        try {
            File file = new File(filename);
            if (file.exists()) {
                FileReader fr = new FileReader(file);
                BufferedReader br = new BufferedReader(fr);
                String str = "";
                while ((str = br.readLine()) != null) {
                    content +=   str;
                }
                br.close();
                fr.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return content;
    }

}
